//
//  YMStackMoreView.swift
//  YMSwiftUI
//
//  Created by anscen on 2022/4/24.
//

import SwiftUI

struct YMStackMoreView: View {
    @State var id :String
    @State private var listData :[YMBook] = []
    var body: some View {
        GeometryReader.init { root in
            VStack {
                List(listData,id: \.self) { item in
                    YMListCell(book: item,width: root.size.width)
                }.onAppear {
                    self.loadData()
                }.navigationBarTitle("更多").listStyle(.plain).navigationBarBackButtonHidden(true).navigationBarItems(leading: BaseNavigationBarBackButton())
            }
        }
    }
    func loadData(){
        ApiMoya.request(target: .homeHot(self.id)) { json, message in
            let rank = json["ranking"]
            let data = [YMBook].deserialize(from: rank["books"].rawString())
            if let list = data as? [YMBook]{
                self.listData = list
            }
        } failure: { error in
            
        }
    }
}

//struct YMStackMoreView_Previews: PreviewProvider {
//    static var previews: some View {
//        YMStackMoreView()
//    }
//}
